package cn.itcast.bos.service.base.impl;

import cn.itcast.bos.dao.base.StandardRepository;
import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StandardServiceImpl implements StandardService {

    @Autowired
    private StandardRepository standardRepository;

    @Override
//    @CacheEvict(value = "standard", allEntries = true)
    public void save(Standard standard) {
        standardRepository.save(standard);
    }

    @Override
    @Cacheable(value = "standard",key = "#pageable.pageNumber+'_'+#pageable.pageSize")
    public Page<Standard> findPageData(Pageable pageable) {
        System.out.println("查询sql..");
        return standardRepository.findAll(pageable);
    }

    @Override
    @Cacheable(value = "standard....................")
    public List<Standard> findAll() {
        System.out.println("查询sql");
        return standardRepository.findAll();
    }

    @Override
    public Standard findById(int i) {
        Standard standard = standardRepository.findById(i);
        return standard;
    }

    @Override
    public List<Standard> findByName(String s) {
        List<Standard> byName = standardRepository.findByName(s);
        return byName;
    }
}
